home *** CD-ROM | disk | FTP | other *** search
-
-
-
- TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee((((3333TTTTkkkk)))) TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee((((3333TTTTkkkk))))
-
-
-
- NNNNAAAAMMMMEEEE
- Tk_Preserve, Tk_Release, Tk_EventuallyFree - avoid freeing storage while
- it's being used
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ####iiiinnnncccclllluuuuddddeeee <<<<ttttkkkk....hhhh>>>>
-
- TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee(_c_l_i_e_n_t_D_a_t_a)
-
- TTTTkkkk____RRRReeeelllleeeeaaaasssseeee(_c_l_i_e_n_t_D_a_t_a)
-
- TTTTkkkk____EEEEvvvveeeennnnttttuuuuaaaallllllllyyyyFFFFrrrreeeeeeee(_c_l_i_e_n_t_D_a_t_a, _f_r_e_e_P_r_o_c)
-
- AAAARRRRGGGGUUUUMMMMEEEENNNNTTTTSSSS
- ClientData _c_l_i_e_n_t_D_a_t_a (in) Token describing structure to be
- freed or reallocated. Usually a
- pointer to memory for structure.
-
- Tk_FreeProc *_f_r_e_e_P_r_o_c (in) Procedure to invoke to free
- _c_l_i_e_n_t_D_a_t_a.
-
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- These three procedures help implement a simple reference count mechanism
- for managing storage. They are designed to solve a problem having to do
- with widget deletion. When a widget is deleted, its widget record (the
- structure holding information specific to the widget) must be returned to
- the storage allocator. However, it's possible that the widget record is
- in active use by one of the procedures on the stack at the time of the
- deletion. This can happen, for example, if the command associated with a
- button widget causes the button to be destroyed: an X event causes an
- event-handling C procedure in the button to be invoked, which in turn
- causes the button's associated Tcl command to be executed, which in turn
- causes the button to be deleted, which in turn causes the button's widget
- record to be de-allocated. Unfortunately, when the Tcl command returns,
- the button's event-handling procedure will need to reference the button's
- widget record. Because of this, the widget record must not be freed as
- part of the deletion, but must be retained until the event-handling
- procedure has finished with it. In other situations where the widget is
- deleted, it may be possible to free the widget record immediately.
-
- TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee and TTTTkkkk____RRRReeeelllleeeeaaaasssseeee implement short-term reference counts for
- their _c_l_i_e_n_t_D_a_t_a argument. The _c_l_i_e_n_t_D_a_t_a argument identifies an object
- and usually consists of the address of a structure. The reference counts
- guarantee that an object will not be freed until each call to TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee
- for the object has been matched by calls to TTTTkkkk____RRRReeeelllleeeeaaaasssseeee. There may be any
- number of unmatched TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee calls in effect at once.
-
- TTTTkkkk____EEEEvvvveeeennnnttttuuuuaaaallllllllyyyyFFFFrrrreeeeeeee is invoked to free up its _c_l_i_e_n_t_D_a_t_a argument. It
- checks to see if there are unmatched TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee calls for the object.
- If not, then TTTTkkkk____EEEEvvvveeeennnnttttuuuuaaaallllllllyyyyFFFFrrrreeeeeeee calls _f_r_e_e_P_r_o_c immediately. Otherwise
- TTTTkkkk____EEEEvvvveeeennnnttttuuuuaaaallllllllyyyyFFFFrrrreeeeeeee records the fact that _c_l_i_e_n_t_D_a_t_a needs eventually to be
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee((((3333TTTTkkkk)))) TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee((((3333TTTTkkkk))))
-
-
-
- freed. When all calls to TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee have been matched with calls to
- TTTTkkkk____RRRReeeelllleeeeaaaasssseeee then _f_r_e_e_P_r_o_c will be called by TTTTkkkk____RRRReeeelllleeeeaaaasssseeee to do the cleanup.
-
- All the work of freeing the object is carried out by _f_r_e_e_P_r_o_c. _F_r_e_e_P_r_o_c
- must have arguments and result that match the type TTTTkkkk____FFFFrrrreeeeeeeePPPPrrrroooocccc:
- typedef void Tk_FreeProc(ClientData _c_l_i_e_n_t_D_a_t_a);
- The _c_l_i_e_n_t_D_a_t_a argument to _f_r_e_e_P_r_o_c will be the same as the _c_l_i_e_n_t_D_a_t_a
- argument to TTTTkkkk____EEEEvvvveeeennnnttttuuuuaaaallllllllyyyyFFFFrrrreeeeeeee.
-
- This mechanism can be used to solve the problem described above by
- placing TTTTkkkk____PPPPrrrreeeesssseeeerrrrvvvveeee and TTTTkkkk____RRRReeeelllleeeeaaaasssseeee calls around actions that may cause
- undesired storage re-allocation. The mechanism is intended only for
- short-term use (i.e. while procedures are pending on the stack); it will
- not work efficiently as a mechanism for long-term reference counts. The
- implementation does not depend in any way on the internal structure of
- the objects being freed; it keeps the reference counts in a separate
- structure.
-
-
- KKKKEEEEYYYYWWWWOOOORRRRDDDDSSSS
- free, reference count, storage
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-